home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 421_01 / keyscan.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  1.6 KB  |  64 lines

  1. // KEYSCAN_C ////////////////////////////////////////////////////////////////
  2.  
  3. // Installs a new keyboard handler
  4.  
  5. // INCLUDES /////////////////////////////////////////////////////////////////
  6.  
  7. #include <bios.h>
  8. #include "keyscan.h"
  9.  
  10. // EXTERNALS ////////////////////////////////////////////////////////////////
  11.  
  12. extern void interrupt newkbdhandler(...);
  13. extern void interrupt (*oldkbdhandler)(...);
  14. extern byte *keypressed;
  15.  
  16. // FUNCTIONS ////////////////////////////////////////////////////////////////
  17.  
  18. void interrupt newkbdhandler(...)
  19. {
  20.   char scan=inportb(0x60);
  21.   pokeb(0,0x417,peekb(0,0x417)&223); // turn off numlock
  22.   oldkbdhandler();
  23.     int mod = bioskey(_NKEYBRD_SHIFTSTATUS);
  24.  
  25.   keypressed[scan&0x7f]=!(scan&0x80);
  26.   keypressed[LALT]=(mod & LALT);
  27.   keypressed[RALT]=(mod & RALT);
  28.   keypressed[LCTRL]=(mod & LCTRL);
  29.   keypressed[RCTRL]=(mod & RCTRL);
  30.   keypressed[CAPSON]=(mod & CAPSON);
  31.   keypressed[NUMON]=(mod & NUMON);
  32.   keypressed[SCROLLON]=(mod & SCROLLON);
  33.   keypressed[INSON]=(mod & INSON);
  34.   poke(0x40,0x1c,peek(0x40,0x1a)); // clear kbd-buffer
  35. }
  36.  
  37. // METHODS //////////////////////////////////////////////////////////////////
  38.  
  39. // CONSTRUCTOR
  40.  
  41. keyscan_C::keyscan_C()
  42. {
  43.   keypressed=new byte[128];
  44.   for(int cl=0;cl<128;cl++)
  45.     keypressed[cl]=0;
  46.   oldkbdhandler=getvect(0x09);
  47.   asm cli
  48.   setvect(0x09,newkbdhandler);
  49.   pokeb(0,0x417,peekb(0,0x417)&223); // turn off numlock
  50.   pokeb(0,0x0500,1);
  51.   asm sti
  52. }
  53.  
  54. // DESTRUCTOR
  55.  
  56. keyscan_C::~keyscan_C()
  57. {
  58.   if (keypressed)
  59.     delete keypressed;
  60.   setvect(0x09,oldkbdhandler);
  61. }
  62.  
  63.  
  64.